const { HS } = require("./Homestead");
const { IntentCreep, CreepBehavior } = require("./Overtick");
require("./HomesteadBehavior");
/**

[remote "origin"]
	url = https://gitee.com/mingzey/homestead.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master

 */


let myCreep = new IntentCreep("myCreep");
let MyBehavior = class MyBehavior extends CreepBehavior{
	do(){//开始该行为时调用
		console.log(`Hello ${this.getCreepName()}`);
	}

	exception(e){//遇到问题时触发

	}

	finished(){//该行为结束时触发

	}
}
myCreep.set(MyBehavior);
module.exports.loop = function(){

	myCreep.next();

	HS.loop();//Homestead 接管

	//简单防御
	let room = Game.rooms.E56S28;
	let targets = room.find(FIND_HOSTILE_CREEPS);
	if(targets.length > 0){
		let tower = Game.getObjectById("620415cd896d0d97f7b7f9bb");
		if(tower.attack(targets[0]) == ERR_NOT_ENOUGH_ENERGY){
			room.activateSafeMode()
		}
	}

	if(Game.cpu.bucket == 10000){
		Game.cpu.generatePixel();
	}

}


// require("ConsoleCRS");
// global.roomMask = new CRSRoomMask("mark");
// roomMask.onCreate(function(scope){
// 	this.selectObj = null;

// 	this.style.padding = "20px";
//     this.style.color = "#fff";
//     this.style.fontSize = "12px";

//     let text = document.createElement("DIV");
//     text.innerHTML = "CRSRoomMask 圣诞版测试 V2.0";
// 	this.appendChild(text);
	
//     let button = document.createElement("Button");
//     button.style.background = "#ffc107";
//     button.style.pointerEvents = "all";
//     button.innerText = "按钮测试！";
//     button.onclick = function(){
//         alert("牛逼！哈哈哈");
//         console.log(666)
//     }
//     this.appendChild(button);


// 	let posText = document.createElement("DIV");
// 	posText.innerText = "POS here";
// 	posText.className = "maskPos";
// 	this.appendChild(posText);
	
// 	let selectObj = document.createElement("DIV");
// 	selectObj.innerText = "Select here";
// 	selectObj.className = "maskSelected";
// 	this.appendChild(selectObj);

// 	let followBox = document.createElement("DIV");
// 	followBox.className = "followBox";
// 	followBox.style.padding = "5px";
// 	followBox.style.background = "#212121";
// 	followBox.style.border = "2px solid rgb(63,81,181)";
// 	followBox.style.opacity = "0";
// 	followBox.style.borderRadius = "5px";
// 	followBox.style.position = "absolute"
// 	followBox.style.transition = "all 2.5s";
// 	followBox.style.color = "#fff";
// 		let title = document.createElement("DIV");
// 		title.className = "followBoxTitle";
// 		followBox.appendChild(title);


// 		let followButton = document.createElement("DIV");
// 		followButton.innerText = "说点什么吧！";
// 		followButton.style.padding = "5px";
// 		followButton.style.background = "#FFC107";
// 		followButton.style.borderRadius = "3px";
// 		followButton.style.pointerEvents = "all";
// 		let that = this;
// 		followButton.onclick = function(){
// 			CRSCore.sendCommand(`Game.getObjectById('${that.selectObj._id}').say("啊哈哈哈哈")`);
// 		}
// 		followBox.appendChild(followButton);
// 		let web = document.createElement("IFRAME");
//         web.style.width = "1000px";
//         web.style.height = "800px";
// 		web.src = "https://www.bilibili.com/?spm_id_from=333.976.b_696e7465726e6174696f6e616c486561646572.1";
// 		web.style.pointerEvents = "all";
// 		followBox.appendChild(web);
// 	this.appendChild(followBox);


// })
// roomMask.onLoop(function(){
// 	let followBox = this.getElementsByClassName("followBox")[0];
// 	if(this.selectObj != null){
// 		followBox.style.opacity = "1";
// 		followBox.style.left = `${this.selectObj.x*2+4}%`;
// 		followBox.style.top = `${this.selectObj.y*2}%`;

// 		let title = this.getElementsByClassName("followBoxTitle")[0];
// 		let obj = this.selectObj;
// 		let str = "";
// 		str += obj.type.toUpperCase() + "\n";
// 		str += `name:${obj.name}\n`;
// 		str += `x: ${obj.x} y:${obj.y}\n`
// 		title.innerText = str;

// 	}else{
// 		followBox.style.opacity = "0";
// 	}
// });

// roomMask.onRoomChange(function(name){
// 	console.log(name);
// })
// roomMask.onCursorPosChange(function(pos){
// 	// console.log(this);
// 	let text = this.getElementsByClassName("maskPos")[0];
// 	text.innerText = JSON.stringify(pos);
// })
// roomMask.onSelectedChange(function(obj){
// 	this.selectObj = obj;
// 	let view = this.getElementsByClassName("maskSelected")[0];
// 	if(obj == null){
// 		view.innerHTML = "未选择";
// 		return;
// 	}
// 	view.innerHTML = obj._id;
// })
// roomMask.onDestroy(function(){
// 	console.log("摧毁");
// })
// roomMask.reload();
